package domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
//import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;


@ManagedBean(name="dtSslObjectView")
@ViewScoped
public class SslObjectView implements Serializable {

	private static final long serialVersionUID = 4224264678188968598L;
	private List<SslObject> SslObjects;
	
	private SslObject selectedSslObject;
	
	private String message;
	private String longMessage;
	
	private String urlToTestOrAdd;
	
    public void addButtonAction(ActionEvent actionEvent) {
        SslObject sslObjectToTest = new SslObject(urlToTestOrAdd, null, null);
        
        SslInvoker SI = new SslInvoker();
        SI.doTest(sslObjectToTest);
        
        if (SI.isSucces()) {        	
        	SslObjects.add(sslObjectToTest);
        }
        
        message = SI.getShortMessage();
        longMessage = SI.getLongMessage();
        
        urlToTestOrAdd = "";
    }
    
    public void testButtonAction(ActionEvent actionEvent) {
        message = this.urlToTestOrAdd + " test";
    }
    
	@PostConstruct
	public void SslObjectInit() {
		SslObjects = new ArrayList<SslObject>();
		//TODO: initier her.
	}

	public List<SslObject> getSslObjects() {
		return this.SslObjects;
	}

	public SslObject getSelectedSslObject() {
		return selectedSslObject;
	}

	public void setSelectedSslObject(SslObject selectedSslObject) {
		this.selectedSslObject = selectedSslObject;
	}
//
//	public void setMessage(String message) {
//		this.message = message;
//	}

	public String getMessage() {
		return message;
	}

	public String getLongMessage() {
		return longMessage;
	}
	
	public String getUrlToTestOrAdd() {
		return urlToTestOrAdd;
	}

	public void setUrlToTestOrAdd(String urlToTestOrAdd) {
		this.urlToTestOrAdd = urlToTestOrAdd;
	}
	
}
